package cn.jcet.mapreduce.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/11 0:21
 * bean为key 电话号为value
 */
public class FlowMapper extends Mapper<LongWritable,Text,FlowBean,Text> {

    private FlowBean k = new FlowBean();
    private Text v = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();

        String[] fileds = line.split("\t");

        String phoneNum = fileds[0];
        // 获取上行流量和下行流量
        long upFlow = Long.parseLong(fileds[1]);
        long downFlow = Long.parseLong(fileds[2]);
        long sumFlow = Long.parseLong(fileds[3]);
        // 数据封装
        k.setUpFlow(upFlow);
        k.setDownFlow(downFlow);
        k.setSumFlow(sumFlow);
        // 封装value
        v.set(phoneNum);
        // 写出
        context.write(k,v);
    }
}
